package cn.tedu.store.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import cn.tedu.store.bean.Goods;
import cn.tedu.store.mapper.GoodsMapper;

@Service("goodsService")
public class GoodsServiceImpl implements IGoodsService {
	private Integer countPerPage=COUNT_PER_PAGE;
	
	public void setCountPerPage(int countPerPage) {
		if(countPerPage>=5 && countPerPage<=30) 
		{
			this.countPerPage=countPerPage;
		}
	}
	public Integer getCountPerPage() {
		return this.countPerPage;
	}
	
	@Resource(name="goodsMapper")
	private GoodsMapper goodsMapper;

	public List<Goods> getGoodsListByCategoryId(Integer categoryId, String orderBy, Integer offset, Integer count) {
		
		return goodsMapper.getGoodsListByCategoryId(categoryId, orderBy, offset, count);
	}

	public List<Goods> getGoodsListByCategoryId(Integer categoryId, Integer offset, Integer count) {
		
		return goodsMapper.getGoodsListByCategoryId(categoryId, "priority DESC", offset, count);
	}

	public List<Goods> getGoodsListByCategoryId(Integer categoryId, String orderBy, Integer page) {
		Integer offset=(page-1)*getCountPerPage();
		Integer count=getCountPerPage();
		return getGoodsListByCategoryId(categoryId, orderBy,offset,count);
	}

	public List<Goods> getGoodsListByCategoryId(Integer categoryId, Integer page) {
		
		return getGoodsListByCategoryId(categoryId,"priority DESC",page);
	}

	public List<Goods> getGoodsListByCategoryId(Integer categoryId, String orderBy) {
		 
		return getGoodsListByCategoryId(categoryId,orderBy,1);
	}

	public List<Goods> getGoodsListByCategoryId(Integer categoryId) {
		
		return getGoodsListByCategoryId(categoryId,"priority DESC",1);
	}
	
	/**
	 * 查出商品分类下的商品的总数
	 * @param category
	 * @return
	 */
	public Integer getGoodsCountByCategoryId(Integer category) {
		return goodsMapper.getGoodsCountByCategoryId(category);
	};
}
